package com.xinzhidi.web.task;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.xinzhidi.common.constant.AgreementConstants;
import com.xinzhidi.web.netty.entity.DeviceInstruction;
import com.xinzhidi.web.netty.service.DeviceInstructionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 检查消息回复是否超时
 *
 * @author cx
 */
@Component("checkMessage")
public class CheckMessageTask {

    @Autowired
    private DeviceInstructionService deviceInstructionService;

    public void ryNoParams() {
        this.checkMessage();
    }

    /**
     * 下发消息
     **/
    private String checkMessage() {
        //获取已下发，但一直未回复的消息
        List<DeviceInstruction> list = deviceInstructionService.getNoReplyMessage();
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        list.stream().forEach(deviceInstruction -> deviceInstruction.setStatus(AgreementConstants.InstructSendingState.RETURN_TIMEOUT));
        deviceInstructionService.updateBatchById(list);
        return null;
    }
}
